package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api("店铺接口")
@RequestMapping("/admin/shop")
@RestController("adminShopController")
public class ShopController {

    public static final String key = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    @ApiOperation("设置店铺营业状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("店铺营业状态设置：{}",status);
        //设置1是1 0是0
        redisTemplate.opsForValue().set(key,status);
        ZSetOperations zSetOperations = redisTemplate.opsForZSet();

        return Result.success();
    }

    @GetMapping("/{status}")
    @ApiOperation("获取店铺的营业状态")
    public Result getStatus(){
        //获取店铺营业状态码，强转是Number数字整数类型进行判断
        Integer status = (Integer) redisTemplate.opsForValue().get(key);

        log.info("店铺营业状态获取：{}",status);
        //返回前端营业状态码
        return Result.success(status);
    }
}
